package com.rop.znyx.activity.controller;

import com.rop.znyx.activity.service.SecKillTimeService;
import com.rop.znyx.common.result.Result;
import com.rop.znyx.model.activity.SecKillTime;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * User: Rop
 * Date: 2023/7/11
 * Time: 9:48
 * Description:
 */

@Api(tags = "秒杀场次管理")
@RestController
@RequestMapping(value = "/admin/activity/SecKillTime")
@RequiredArgsConstructor
public class SecKillTimeController {

    private final SecKillTimeService SecKillTimeService;

    /**
     * 获取分页列表
     */
    @ApiOperation(value = "获取分页列表")
    @GetMapping()
    public Result<List<SecKillTime>> index() {
        return Result.ok(SecKillTimeService.list());
    }

    /**
     * 获取
     */
    @ApiOperation(value = "获取")
    @GetMapping("get/{id}")
    public Result<SecKillTime> get(@PathVariable Long id) {
        SecKillTime SecKillSession = SecKillTimeService.getById(id);
        return Result.ok(SecKillSession);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增")
    @PostMapping("save")
    public Result<Boolean> save(@RequestBody SecKillTime SecKillSession) {
        boolean isSuccess = SecKillTimeService.save(SecKillSession);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PutMapping("update")
    public Result<Boolean> updateById(@RequestBody SecKillTime SecKillSession) {
        boolean isSuccess = SecKillTimeService.updateById(SecKillSession);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public Result<Boolean> remove(@PathVariable Long id) {
        boolean isSuccess = SecKillTimeService.removeById(id);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 根据id列表删除
     */
    @ApiOperation(value = "根据id列表删除")
    @DeleteMapping("batchRemove")
    public Result<Boolean> batchRemove(@RequestBody List<Long> idList) {
        boolean isSuccess = SecKillTimeService.removeByIds(idList);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 更新状态
     */
    @ApiOperation(value = "更新状态")
    @PostMapping("updateStatus/{id}/{status}")
    public Result<Boolean> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        boolean isSuccess = SecKillTimeService.updateStatus(id, status);
        return isSuccess ? Result.ok() : Result.fail();
    }

}
